﻿//该js用于处理房源跟进权限相关逻辑
var PropertyFollowRight = {};
var pfr = PropertyFollowRight;
//部门上删除跟进的权限
pfr.DdelRight = "Property.Follow.Delete-All";
//角色删除本人跟进权限
pfr.RdelSelf = "Property.Follow.Delete-MySelf";
//角色删除本部跟进权限
pfr.RdelDepart = "Property.Follow.Delete-MyDepartment";
//角色删除全部跟进权限
pfr.RdelAll = "Property.Follow.Delete-All";


//部门上置顶跟进的权限
pfr.DtopRight = "Property.Follow.Top-All";
//角色置顶本人跟进权限
pfr.RtopSelf = "Property.Follow.Top-MySelf";
//角色置顶本部跟进权限
pfr.RtopDepart = "Property.Follow.Top-MyDepartment";
//角色置顶全部跟进权限
pfr.RtopAll = "Property.Follow.Top-All";
//验证跟进删除权限
//follows是跟进集合,其中必须包含PropertyDepartmentKeyId,跟进房源做属部门
//DepartmentPermissions 操作人对跟进所属房源的部门权限
//keyid 跟进id
//estateName 房源楼盘
//userid 跟进填写人
//用于跟进左导页的跟进删除
PropertyFollowRight.CheckDelRight = function (follows,roleRight,myDepartments,operator) {
    for (var i = 0; i < follows.length; i++) {
        var item = $(follows[i]);
        //判断操作人是否有删除所属房源跟进的部门权限,比如A部门能不能删除房源B的跟进
        if (item.attr("DepartmentPermissions").indexOf(pfr.DdelRight) == -1) {
            $.OKDialogAgency('<div class="tc">您所在部门没有删除' + item.attr('estateName') + '跟进的权限！</div>');
            return false;
        }
        //如果有部门权限,那么判断角色权限
        //本人
        if (roleRight.indexOf(pfr.RdelSelf) > -1) {
            if (item.attr("userid") != operator) {
                $.OKDialogAgency('<div class="tc">您拥有的是删除本人跟进的权限,但您试图删除不属于您填写的跟进！</div>');
                return false;
            }
        }
        else if (roleRight.indexOf(pfr.RdelDepart) > -1) {
            if (myDepartments.indexOf(item.attr("PropertyDepartmentKeyId")) == -1) {
                $.OKDialogAgency('<div class="tc">您拥有的是删除本部跟进的权限,但您试图删除不属您管辖部门的跟进！</div>');
                return false;
            }
        }
        else {
            $.OKDialogAgency('<div class="tc">您没有删除跟进的权限！</div>');
            return false;
        }
    }
    return true;
}
//判断用于房源详细页的跟进删除
PropertyFollowRight.CheckDelRightDedail = function () {
        var roleRight = $("#hidPermissions").val();
        //如果有部门权限,那么判断角色权限
        //本人
        if (roleRight.indexOf(pfr.RdelSelf) > -1) {
            if ($("#hidPropertyChiefKeyId").val() != $("#hidOperatorID").val()) {
                $.OKDialogAgency('<div class="tc">您拥有的是删除本人跟进的权限,但该楼盘的所属人不是您！</div>');
                return false;
            }
        }
        else if (roleRight.indexOf(pfr.RdelDepart) > -1) {
            if ($("#hidMyDepartments").val().indexOf($("#hidPropertyChiefDepartmentKeyId").val()) == -1) {
                $.OKDialogAgency('<div class="tc">您拥有的是删除本部跟进的权限,但您试图删除不属您管辖部门的跟进！</div>');
                return false;
            }
        }
        else if (roleRight.indexOf(pfr.RdelAll) > -1) {
            return true;
        }
        else {
            $.OKDialogAgency('<div class="tc">您没有删除跟进的权限！</div>');
            return false;
        }
    
    return true;
}
//判断用于房源详细页的跟进置顶
PropertyFollowRight.CheckTopRightDedail = function () {
    var roleRight = $("#hidPermissions").val();
    //如果有部门权限,那么判断角色权限
    //本人
    if (roleRight.indexOf(pfr.RtopSelf) > -1) {
        if ($("#hidPropertyChiefKeyId").val() != $("#hidOperatorID").val()) {
            $.OKDialogAgency('<div class="tc">您拥有的是置顶本人跟进的权限,但该楼盘的所属人不是您！</div>');
            return false;
        }
    }
    else if (roleRight.indexOf(pfr.RtopDepart) > -1) {
        if ($("#hidMyDepartments").val().indexOf($("#hidPropertyChiefDepartmentKeyId").val()) == -1) {
            $.OKDialogAgency('<div class="tc">您拥有的是置顶本部跟进的权限,但您试图置顶不属您管辖部门的跟进！</div>');
            return false;
        }
    }
    else if (roleRight.indexOf(pfr.RtopAll) > -1) {
        return true;
    }
    else {
        $.OKDialogAgency('<div class="tc">您没有置顶的相关权限！</div>');
        return false;
    }

    return true;
}